<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title><?php echo $title;?></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../public/plugin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../public/css/base.css">
  <link rel="stylesheet" href="../../public/icon/demo.css">
  <link rel="stylesheet" href="../../public/icon/iconfont.css">
  <script src="../../public/icon/iconfont.js"></script>
  <link rel="stylesheet" href="../../public/icon1/demo.css">
  <link rel="stylesheet" href="../../public/icon1/iconfont.css">
  <script src="../../public/icon1/iconfont.js"></script>
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header" style="padding-top:30px;font-size:18px;"><?php echo $title;?>
			<div style="float:right;padding-right:20px;">
				<button class="layui-btn layui-btn-normal" id="csv"><span class="iconfont icon-tuichu"></span>&nbsp;导出CSV</button>
				<button class="layui-btn layui-btn-normal" id="print"><span class="iconfont icon-dayinji"></span>&nbsp;打印</button>
				<button class="layui-btn layui-btn-normal" id="add"><span class="iconfont icon-plus-circle"></span>&nbsp;增加</button>
				<button class="layui-btn layui-btn-normal" id="edit"><span class="iconfont icon-bianji-tianchong"></span>&nbsp;编辑</button>
				<button class="layui-btn layui-btn-normal" id="delete"><span class="iconfont icon-delete "></span>&nbsp;删除</button>
			</div>
		  </div>
          <div class="layui-card-body" pad15>
			<table class="layui-table">
			  <thead>
				<tr>
				<th></th>
				  <th>id</th>
				  <th>题目</th>
				  <th>答案</th>
				  <th>添加时间</th>
				  <th>类型</th>
				</tr> 
			  </thead>
			  <tbody>
			  <?php foreach($list as $k => $v):?>
				<tr>
				<td><input name="radio" type="radio" index="<?php echo $v['id'];?>" /></td>
				  <td><?php echo $v['id'];?></td>
				  <td><?php echo $v['question'];?></td>
				  <td><?php echo $v['answer'];?></td>
				  <td><?php date_default_timezone_set("Asia/Shanghai"); echo date("Y-m-d H:i:s",$v['create_time']);?></td>
				  <td><?php $id = $v['type_id']; if($id==$tlist[$id-1][$id]);echo $tlist[$id-1]['type_name'];?></td>
				</tr>
				<?php endforeach;?>
				<tr>
					<td colspan="6">
					  <div class="pages">
						<?php echo $strPage;?>
					  </div>
					</td>
				</tr>
			  </tbody>
			</table>
			
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>
<script src="../../public/js/jquery.js"></script>
<script src="../../public/plugin/layer/layer.js"></script>
<script>
	$(function() {
		$("#csv").click(function(){
			var tx = '<?php echo $title;?>';
			var index = tx.lastIndexOf("\-");
			tx = tx.substring(index+1,tx.length);
			window.location.href="csv.php?tx="+tx;
		});
		//打印
		$("#print").click(function(){
			window.print();
		});
		//给按钮绑定单击事件
		$('#add').on('click', function() {
			layer.open({
				type: 2,
				title: '添加试题',
				shadeClose: true,
				shade: 0.8,
				area: ['800px', '50%'],
				maxmin: true, //开启最大化最小化按钮
				content: "add_judge.php" //iframe的url
			});
		});
		
		$('#edit').click(function() {
			var index = $("input:checked").attr("index");
			var id = Number(index);
			if(isNaN(id)){
				layer.alert('未选择题目');
			}else{
				layer.open({
					type: 2,
					title: '修改试题',
					shadeClose: true,
					shade: 0.8,
					area: ['800px', '50%'],
					maxmin: true, //开启最大化最小化按钮
					content: "edit_judge.php?id="+id //iframe的url
				});
			}
		});
		  
		
		$("#delete").click(function(){
			var index = $("input:checked").attr("index");
			var id = Number(index);
			if(isNaN(id)){
				layer.alert('未选择题目');
			}else{
				if(confirm("确定删除吗？")){
					var index = $("input:checked").attr("index");
					var id = Number(index);
					var tr = $("input:checked").parent('td').parent('tr');
					//ajax删除
					$.ajax({
						type: "GET",
						url: "ajaxdeletej.php?id="+id,
						success: function(data){
								
								layer.alert(data);
								//移除选中行
								tr.remove();
						}

					});
				};
			}
		});
	});
</script>